<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件


/**
 * 验证字符串格式
 * @param  $num    string   字符串
 * @param  $type   string   类型
 *    $type:phone、email、int、round2
 * @return         boolean|string
 */
function is_reg_str($num,$type = 'phone'){
	//数据验证
	if(empty($num)){
		return false;
	}
	$reg = '';
	//正则书写
    if($type == 'phone'){                  //手机号
    	$reg = '/^1[3456789]\d{9}$/';
    }else if($type == 'email'){            //邮箱
    	$reg = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/';
    }else if($type == 'int'){              //整型数字
    	$reg = '/^[0-9]*$/';
    }else if($type == 'round2'){  		   //保留2为小数的整数
    	$reg = '/^[0-9]+(.[0-9]{2})?$/';  
    }else{
    	return false;
    }
    //正则验证
    $op = preg_match($reg,$num);
    if($op){
    	return $num;//返回
    }	
    return false;
}